//推荐相关方法

const {
    execSQL
} = require('../db/mysql')

//商品数据
const getRecommend = () => {
    let sql = `select data from goods where i IN (${getRandomId()})`;
    return execSQL(sql).then((res) => {
        let list = [];
        if (!res) return false;
        for (let i of res)
            list.push(JSON.parse(i.data))
        return list;
    }).catch(e => {
        return false;
    })

}

function getRandomId() {
    let str = '',
        times = 20;
    while (times--) {
        str += `'${(Math.floor(Math.random()*1940))}',`
    }
    return str.slice(0, -1);
}




module.exports = {
    getRecommend,
}